package com.lyr.thread;

public class MyThread extends Thread{
    // 终止变量
    private boolean stopped;

    public MyThread(String name) {
        super(name);
    }

    @Override
    public void run() {
        int i=0;
        // 无循环因子，此为死循环
        for (;;){
            try {
                // 多线程业务处理
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println(this.getName()+": "+i++);
            // 判断是否需要终止线程
            if (stopped){
                break;
            }
        }
    }

    public boolean isStopped() {
        return stopped;
    }

    public void setStopped(boolean stopped) {
        this.stopped = stopped;
    }
}
